import React from 'react';
import ReactDOM from 'react-dom';

class Sum extends React.Component {
  add = () => {
    //Property 'value' does not exist on type 'ReactInstance'
    //将其断言为HTMLInputElement解决
    let a = (this.refs.a as HTMLInputElement).value;
    let b = (this.refs.b as HTMLInputElement).value;
    (this.refs.c as HTMLInputElement).value = (parseInt(a) + parseInt(b)) + '';
  };

  render() {
    return (
      <>
        {/* ref的值可以是个字符串 */}
        <input ref="a"/>+
        <input ref="b"/>
        <button onClick={this.add}>=</button>
        <input ref="c"/>
      </>
    );
  }
}

ReactDOM.render(<Sum/>, document.getElementById('root'))
